import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_customer/ful_components/business_customer_details_edit_address_tab.dart';
import 'package:x3_business_core/business_customer/ful_components/business_customer_details_edit_base_tab.dart';
import 'package:x3_business_core/business_customer/ful_components/business_customer_details_edit_label_tab.dart';

class BusinessCustomerDetailsEdit extends StatefulWidget {

  static final String sName = 'newvip/edit';

  @override
  _BusinessCustomerDetailsEditState createState() => _BusinessCustomerDetailsEditState();

}

class _BusinessCustomerDetailsEditState extends State<BusinessCustomerDetailsEdit> {

  BaseTabBarPage _tabPage;

  @override
  Widget build(BuildContext context) {
    return BaseScaffoldComponent(
      title: '完善资料',
      child: BaseScreenRefreshComponent(
        request: BaseScreenRequestModel('/vipbills/vipuserbills/vipclerk/static/param', method: BaseHttpMethodEnum.GET),
        builder: _buildContent,
        serviceType: BaseScreenRefreshServiceType.Response,
      ),
    );
  }

  Widget _buildContent(BaseHttpResultModel result) {
    List<BaseHttpResponseModel> responses = BaseTransformUtil.transformToListResponseData(result.data);
    responses.removeWhere((element) => element.fieldName == "contentTagTitle");
    List<BaseTabConfig> tabs = responses.map((response) => BaseTabConfig(text: response.name, child: _buildTabBarViewWidget(response))).toList();
    this._tabPage = BaseTabBarPage(tabs);
    return Column(children: [
      _tabPage.buildTabBar(context),
      Expanded(child: _tabPage.buildTabView()),
    ]);
  }

  Widget _buildTabBarViewWidget(BaseHttpResponseModel response) {
    dynamic arguments = BaseRouterUtil.getArguments(context);
    String vipId = BaseUtils.getKeyData(arguments, 'vipId').toString();
    switch (response.fieldName) {
      case 'contentBaseTitle':
        return BusinessCustomerDetailsEditBaseTab(response: response, vipId: vipId);
        break;
      case 'contentTagTitle':
        return BusinessCustomerDetailsEditLabelTab(response: response, vipId: vipId);
        break;
      case 'contentAddressTitle':
        return BusinessCustomerDetailsEditAddressTab(response: response, vipId: vipId);
        break;
    }
    return Text('未知的Tab');
  }

  @override
  void dispose() {
    _tabPage.dispose();
    super.dispose();
  }

}
